﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using AspNetCs.Common;
using AspNetCs.Bll;
using AspNetCs.Enumerations.Channel_Enum;
using System.Data;

public partial class Script_ScriptAlms : BasePage
{

    protected string Cnt = "";
    protected int id = 0;
    protected string channelStr = "";
    protected int num = 10;
    protected string Objid = "AlmsId";

    protected string ExecuteObj = "";


    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request["id"] != null)
        {
            id = StringHelper.isNumber_int(Request["id"].ToString());
        }
        if (Request["Objid"] != null)
        {
            Objid = Request["Objid"].ToString();
        }
        if (Objid.Trim() + "" == "")
        {
            Objid = "AlmsId";

        }

        if (Request["channel"] != null)
        {
            channelStr = Request["channel"].ToString();
        }
        if (Request["num"] != null)
        {
            num = StringHelper.isNumber_int(Request["num"].ToString());
        }
        if (Request["ExecuteObj"] != null)
        {
            ExecuteObj = Request["ExecuteObj"].ToString();
        }
        if (ExecuteObj == "Ok")
        {
            string Content = "";

            if (Request["Cnt"] != null)
            {
                Content = Request["Cnt"].ToString();
                Cnt = Content;
            }
            GetStringData_lable lb = new GetStringData_lable();
            DataTable dt = AlmsBll.CreateNew.GetDataTable(" state=1 and  TypeId=" + id + " and channelId='" + channelStr + "' order by addtime desc ");

            if (dt.Rows.Count > 0)
            {
                string str = "";
                int i = 0;
                DataTable dt2 = new DataTable();
                dt2 = dt.Clone();
                foreach (DataRow dr in dt.Rows)
                {

                    DataRow dr2 = dt2.NewRow();//如果在此直接用dt2.Rows.Add(Drr)会报错，因为Drr的引用现在为 dt1所用
                    dr2.ItemArray = dr.ItemArray;
                    dt2.Rows.Add(dr2);
                    str += lb.GetResultStr(Cnt, dt2);
                    i++;
                    dt2.Clear();
                    if (i >= num) { break; }
                }


                Response.Write(str);
            }
            else
            {
                Response.Write("<center>暂无功德募捐</center>");
            }
            Response.End();




        }




    }

    protected void BindAlms()
    {
        StringBuilder stb = new StringBuilder();

        stb.AppendLine("var _this=$(\"#" + Objid + "\");");
        stb.AppendLine("if(_this.length>0)");
        stb.AppendLine("{");

        stb.AppendLine("$.ajax({");
        stb.AppendLine("url:\"" + configInfo.InstallDir + "Script/ScriptAlms.Aspx?ExecuteObj=Ok&num=" + num + "&id=" + id + "&channel=" + channelStr + "&rnd=\"+Math.random(),");
        stb.AppendLine("type: 'POST',");
        stb.AppendLine("data: 'Cnt='+escape(_this.html()),");
        stb.AppendLine("dataType: \"html\",");
        stb.AppendLine("beforeSend: function() {");

        stb.AppendLine("_this.html(\"<img src='" + configInfo.InstallDir + "images/007.gif' align='absmiddle' >加载中...\");");


        stb.AppendLine("},");

        stb.AppendLine("error:function(data) {");

        stb.AppendLine("_this.html('错误!');");

        stb.AppendLine("},");

        stb.AppendLine("success:function(data)  {");
        stb.AppendLine("_this.html(data);");



        stb.AppendLine("},");
        stb.AppendLine("complete:function(data,textStatus) {");
        stb.AppendLine("}");
        stb.AppendLine("})");
        stb.AppendLine("}");
        Response.Write(stb.ToString());
    }






}
